Socket
Socket
Sign inDemoInstall

jest-environment-node

Package Overview
Dependencies
43
Maintainers
7
Versions
274
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jest-environment-node


Version published
Weekly downloads
24M
decreased by-1.26%
Maintainers
7
Install size
1.81 MB
Created
Weekly downloads
 

Package description

What is jest-environment-node?

The jest-environment-node npm package is a test environment for Jest that simulates a Node.js environment. It is used when testing Node.js specific code. It provides a global environment that's set up for each test file to be executed in a Node-like environment, with all the necessary globals like `process` and `Buffer` available.

What are jest-environment-node's main functionalities?

Simulating Node.js Environment

This configuration in Jest's setup file tells Jest to use the Node environment for testing. It is useful when you want to test code that relies on Node.js APIs.

module.exports = { testEnvironment: 'jest-environment-node' };

Global Setup and Teardown

This feature allows you to extend the Node environment to add custom setup and teardown logic that runs before and after each test suite.

class CustomEnvironment extends NodeEnvironment {
  async setup() {
    await super.setup();
    // Your setup code here
  }

  async teardown() {
    // Your teardown code here
    await super.teardown();
  }
}

Custom Module Mocking

In a Node environment, you can mock Node modules like 'fs' to control their behavior during tests, which is useful for testing code that interacts with the filesystem without actually reading or writing files.

jest.mock('fs', () => ({
  readFileSync: jest.fn().mockReturnValue('mocked content'),
}));

Other packages similar to jest-environment-node

Changelog

Source

26.6.2

Features

  • [jest-core] Add findRelatedTests and nonFlagArgs in allowed config options for updateConfigAndRun in watch plugins (#10659)

Fixes

  • [babel-plugin-jest-hoist] Preserve order of hoisted mock nodes within containing block (#10536)
  • [babel-plugin-jest-hoist] Hoist pure constants to support experimental JSX transform in hoisted mocks (#10723)
  • [babel-preset-jest] Update babel-preset-current-node-syntax to support top level await (#10747)
  • [expect] Revert "Fix objectContaining to work recursively into sub-objects (#10508)" (#10766)
  • [jest-circus, jest-jasmine2] fix: don't assume stack is always a string (#10697)
  • [jest-config] Fix bug introduced in watch mode by PR #10678 (#10692)
  • [jest-config] Throw correct error for missing preset modules (#10737)
  • [jest-resolve-dependencies] Resolve mocks as dependencies (#10713)
  • [jest-runtime] Handle file URLs in dynamic imports (#10744)
  • [jest-runtime, babel-jest] Pass more ESM options to @jest/transform (#10752)
  • [jest-runtime] Properly inject extraGlobals into the runtime (#10758)
  • [jest-transform] Link to ESM docs on syntax errors (#10748)

Chore & Maintenance

  • [docs] Add docs for using mocks in TypeScript (#10415)
  • [eslint-config-fb-strict] Move package from this repo to fbjs repo (#10739)
  • [examples] Update TypeScript example to show use of newer Jest types (#10399)
  • [jest-cli] chore: standardize files and folder names (#10698)
  • [jest-config] Switch ts-node Register type to Service due to deprecation (#11210)

FAQs

Last updated on 02 Nov 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc